package com.ruoyi.gbase.util;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.gbase.domain.GbaseJobInfo;
import com.ruoyi.gbase.domain.TableInfo;
import com.ruoyi.gbase.service.IGbaseJobInfoService;
import com.ruoyi.gbase.service.ITableInfoService;
import com.ruoyi.nsh.util.DateUtil;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查看数据下发文件有没有入库成功 DB2和 Gbase
 * @author ys.yin
 *@since 2020-11-03
 */
@Component
public class SJXFUtil {
	//private static final Log logger = LogFactory.getLog(SJXFUtil.class);

	@Autowired
	private ITableInfoService tableInfoService;

	@Autowired
	private IGbaseJobInfoService gbaseJobInfoService;

	/**
	 * 检测ODS表下发入库是否完成-db2
	 * @param schema 数据库Schema
	 * @param tableName 下发表名
	 * @return boolean
	 */
	public  boolean checkOdsTbRkIsOk_db2(String schema,String tableName){
		String todayStr = DateUtils.getdateYYYYMMDD();
		//昨天日期
		String yestDay = DateUtil.addDay(todayStr, -1);

		boolean isIn=false;

		TableInfo tableInfo = new TableInfo();
		tableInfo.setJobRunStatus(4);
		tableInfo.setEtlDate(yestDay);
		tableInfo.setSchemaName(schema.toUpperCase());
		tableInfo.setTableName(tableName.toUpperCase());
		List<TableInfo> tableInfoList =  tableInfoService.selectTableInfoList(tableInfo);

		if (tableInfoList != null && tableInfoList.size()>0) {
			isIn = true;
		}

		return isIn;
	}


	/**
	 * 检测ODS表下发入库是否完成_Gbase入库是否完成
	 * @param schema 数据库Schema
	 * @param tableName 下发表名
	 * @return boolean
	 */
	public  boolean checkOdsTbRkIsOk_Gbase(String schema,String tableName){
		String todayStr = DateUtils.getdateYYYYMMDD();
		//昨天日期
		String yestDay = DateUtil.addDay(todayStr, -1);

		boolean isIn=false;
		//select JOB_ID, JOB_NAME, ETL_DATE, SCHEMA_NAME, TABLE_NAME, CREATE_TIME ,NUM,END_TIME, SEND_CONDITION,
		// TABLE_CHANGE_FLAG, REMARK,SECNUM from GBASE_JOB_INFO
		GbaseJobInfo gbaseJobInfo = new GbaseJobInfo();
		gbaseJobInfo.setEtlDate(yestDay);
		gbaseJobInfo.setSchemaName(schema.toUpperCase());
		gbaseJobInfo.setTableName(tableName.toUpperCase());
		List<GbaseJobInfo> gbaseJobInfoList =  gbaseJobInfoService.selectGbaseJobInfoList(gbaseJobInfo);

		if (gbaseJobInfoList != null && gbaseJobInfoList.size()>0) {
			isIn = true;
		}

		return isIn;
	}


}
